package com.qingluan.dd.InetTool;

import org.apache.http.Header;
import org.json.JSONObject;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class UpdateMission {
	private Context context;
	public UpdateMission(Context context){
		this.context = context;
	}
	
	public void Update( String url,JSONObject JSON,String key,final AfterSuccessListener listener){
		AsyncHttpClient client = new AsyncHttpClient();
		RequestParams request = new RequestParams();
		client.setTimeout(6000);
		request.put(key, JSON.toString());
		client.post(url,request ,new AsyncHttpResponseHandler(){
			@Override
			public void onSuccess(String resultCode){
				listener.AfterSuccess(resultCode);
			}
			
			@Override
			public void onFailure(int statusCode, Header[] headers
					, byte[] binaryData, Throwable error){
				Log.d("I_CACHE","error"+error.toString());
			/*  测试时开启
				for (Header head : headers){
					Log.d(TAG,head.getName() + "/"+head.getValue());
				}
			 */
				Toast.makeText(context, "Internet error", Toast.LENGTH_SHORT).show();
			}
		});
	}
	
	public interface AfterSuccessListener {
		public void AfterSuccess(String resultCode);
	}
}
